package com.zy.yun.controller.sys;

import com.zy.yun.base.common.RestResult;
import com.zy.yun.provider.service.IUserService;
import org.apache.http.NameValuePair;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 王彦委
 * @Description: 后台用户登录
 * @Date: 22:17 2019/10/25
 */
@RestController
public class LoginController {



    @Autowired
    private IUserService userService;

    private static final CloseableHttpClient httpclient = HttpClients.createDefault();

    /**
      * @Author: 王彦委
      * @Description: 用户登录
      * @Date: 22:18 2019/10/25
      */
    @RequestMapping("doLogin")
    public RestResult login(String username, String password, HttpServletResponse response, HttpServletRequest request) throws IOException {

        List<NameValuePair> formparams = new ArrayList<NameValuePair>();

//        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
//        userQueryWrapper.eq("name", username);
//
//        formparams.add(new BasicNameValuePair("grant_type", "password"));
//        formparams.add(new BasicNameValuePair("scope", "all"));
//        formparams.add(new BasicNameValuePair("password", password));
//        formparams.add(new BasicNameValuePair("username", username));
//        formparams.add(new BasicNameValuePair("client_id", "client_1"));
//        formparams.add(new BasicNameValuePair("client_secret", "123456"));
//
//        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
//
//        HttpPost httpPost = new HttpPost("http://localhost:8080/oauth/token");
//        httpPost.setEntity(entity);
//        CloseableHttpResponse response = httpclient.execute(httpPost);
//        HttpEntity result = response.getEntity();
//        String s = EntityUtils.toString(result);
//        System.err.println(s);


        return  RestResult.buildSuccess();
    }
}
